import {BasicColumn, FormSchema} from "/@/components/Table";
import {EpibolyUnitQueryConditionDto} from "/@/api/ehs/model/epibolyModel";
import {Tag} from "ant-design-vue";
import {h} from "vue";

//相关单位的数据
/**
 * 相关方单位的数据表头
 */
export const EpibolyUnitTableColumn: BasicColumn[] = [
    {
        title: '名称',
        dataIndex: 'unitname',
        width: 60,
    },
    {
        title: '类型',
        dataIndex: 'type',
        width: 50,
    },
    {
        title:'安全责任人',
        dataIndex: 'resname',
        width: 40,
    },
    {
        title: '状态',
        dataIndex: 'status',
        width: 30,
        customRender:({record})=>{
            const status = Number(record.status);
            const color = status === 1 ? 'green' : status === 2 ? 'orange' : 'black';
            const text = status === 1 ? '合作中' : status === 2 ? '已结束' : '黑名单';
            return h(Tag, { color }, () => text);
        }
    },
    {
        title: '介绍信息',
        dataIndex: 'description',
        width: 50,
        ifShow: false,
    },
]

/**
 * 相关方单位查询条件表单
 */
export const EpibolyUnitQueryConditionFormSchema:FormSchema[] =[
    /**
     * 关键字，模糊匹配单位名称、类型、负责人、介绍信息
     */
    {
        field:'keywords',
        label: '关键字',
        component: 'Input',
        colProps: {
            span: 9,
        },
        componentProps: {
            placeholder: '请输入关键字',
        },
    },

    /**
     * 状态
     */
    {
        field:'status',
        label: '状态',
        component: 'Select',
        required: false,
        colProps: {
            span: 7,
        },
        componentProps: {
            placeholder: '请选择状态',
            options: [
                {
                    label: '合作中',
                    value: '1',
                },
                {
                    label: '已结束',
                    value: '2',
                },
                {
                    label: '黑名单',
                    value: '3',
                }
            ]
        }
    }

]

/**
 * 定义新增/修改时许数据表单
 */
export const EpibolyUnitFormSchema:FormSchema[] = [
    {
        field:'unitid',
        label: '单位id',
        component: 'Input',
        required: false,
        ifShow: false,
    },
    {
        field:'orgcode',  // 添加组织代码字段
        label: '组织代码',
        component: 'Input',
        required: false,
        ifShow: false,  // 隐藏字段，用于存储组织代码
    },
    {
        field:'unitname',
        label: '单位名称',
        component: 'Input',
        required: true,
    },

    {
        field:'type',
        label: '类型',
        component: 'AutoComplete',
        required: true,
        componentProps: {
            placeholder: '请输入类型',
            options: [
                {
                    label: '供应商',
                    value: '供应商',
                },
                {
                    label: '施工单位',
                    value: '施工单位',
                },
                {
                    label: '监理',
                    value: '监理',
                }
            ]
        }
    },
    {
        field:'resname',
        label: '安全责任人',
        component: 'Input',
        required: false,
    },
    {
        field:'resphone',
        label: '安全责任人电话',
        component: 'Input',
        required: false,
    },
    {
        field:'status',
        label: '状态',
        component: 'Select',
        required: true,
        defaultValue: '1',
        componentProps: {
            options: [
                {
                    label: '合作中',
                    value: '1',
                },
                {
                    label: '已结束',
                    value: '2',
                },
                {
                    label: '黑名单',
                    value: '3',
                }
            ]
        }
    },
    {
        field:'description',
        label: '介绍信息',
        component: 'Input',
        required: false,
    },

]


//相关人员的数据
/**
 * 相关方人员的数据表头
 */
export const EpibolyPersonTableColumn: BasicColumn[] = [
    {
        title:'人员ID',
        dataIndex: 'id',
        width: 50,
        ifShow:false
    },
    {
        title: '名称',
        dataIndex: 'name',
        width: 30,
    },
    {
        title: '单位ID',
        dataIndex: 'unitid',
        width: 50,
        ifShow:false

    },
    {
        title: '组织代码',
        dataIndex: 'orgcode',
        width: 50,
        ifShow:false,

    },
    {
        title: '身份证号码',
        dataIndex: 'idnumber',
        width: 50,
    },
    {
        title: '电话',
        dataIndex: 'phone',
        width: 40,
    },
    {
        title: '状态',
        dataIndex: 'status',
        width: 30,
        customRender:({record})=>{
            const status = Number(record.status);
            const color = status === 1 ? 'green' : status === 2 ? 'orange' : 'black';
            const text = status === 1 ? '合作中' : status === 2 ? '已结束' : '黑名单';
            return h(Tag, { color }, () => text);
        }
    }
]

/*
* 定义新增/修改时数据表单
* */
export  const EpibolyPersonFormSchema: FormSchema[] = [
    {
        field:'id',
        label: '人员id',
        component: 'Input',
        required: false,
        show: false,
    },
    {
        field:'name',
        label: '人员姓名',
        component: 'Input',
        required: true,
    },
    {
        field:'unitid',  // 修改：从 'id' 改为 'unitid'，与数据库字段匹配
        label: '单位id',
        component: 'Input',
        required: true,
        ifShow: false,
    },
    {
        field:'orgcode',  // 添加组织代码字段
        label: '组织代码',
        component: 'Input',
        required: true,
        ifShow: false,  // 隐藏字段，用于存储组织代码
    },
    {
        field:'idnumber',
        label: '身份证号码',
        component: 'Input',
        required: false,
    },
    {
        field:'phone',
        label: '电话',
        component: 'Input',
        required: false,
    },
    {
        field:'status',
        label: '状态',
        component: 'Select',
        required: true,
        defaultValue: '1',
        componentProps: {
            options: [
                {
                    label: '合作中',
                    value: '1',
                },
                {
                    label: '已结束',
                    value: '2',
                },
                {
                    label: '黑名单',
                    value: '3',
                }
            ]
        }
    },
    {
        field:'description',
        label: '介绍信息',
        component: 'Input',
        required: false,
    },
 ]

/*
* 相关方证照滑块的表头
* */
export const certificateInfoDrawerTableColumns: BasicColumn[] = [
    {
        title: '资质证照ID',
        dataIndex: 'id',
        fixed: 'left',
        width: 100,
        ifShow: false,
    },
    {
        title: '组织代码',
        dataIndex: 'orgcode',
        fixed: 'left',
        width: 100,
        ifShow: false,
    },
    {
        title: '资质证照名称',
        dataIndex: 'name',
        width: 100,
        ifShow: true,
        sorter: (a, b) => {
            // 处理空值情况
            if (!a.name && !b.name) return 0;
            if (!a.name) return -1;
            if (!b.name) return 1;

            // 使用 localeCompare 进行中文排序
            return a.name.localeCompare(b.name, 'zh-CN', {
                numeric: true,        // 数字排序
                sensitivity: 'base'   // 不区分大小写
            });
        },
        sortDirections: ['ascend', 'descend'],
        defaultSortOrder: 'ascend' // 默认按名称正序（A-Z）
    },
    {
        title: '资质证照类型',
        dataIndex: 'type',
        width: 100,

    },
    {
        title: '资质证照编号',
        dataIndex: 'no',
        width: 100,
    },
    {
        title: '发证机构',
        dataIndex: 'authority',
        width: 100,

    },
    {
        title: '发证时间',
        dataIndex: 'assigntm',
        width: 100,
        sorter: (a, b) => {
            // 处理空值情况
            if (!a.assigntm && !b.assigntm) return 0;
            if (!a.assigntm) return -1;
            if (!b.assigntm) return 1;

            // 将日期字符串转换为Date对象进行比较
            const dateA = new Date(a.assigntm);
            const dateB = new Date(b.assigntm);
            return dateA.getTime() - dateB.getTime();
        },
        sortDirections: ['descend', 'ascend'],
    },
    {
        title: '过期时间',
        dataIndex: 'expiredtm',
        width: 100,
        sorter: (a, b) => {
            // 处理空值情况（空值表示不过期，应该排在最后）
            if (!a.expiredtm && !b.expiredtm) return 0;
            if (!a.expiredtm) return 1;  // 不过期的排在后面
            if (!b.expiredtm) return -1; // 不过期的排在后面

            // 将日期字符串转换为Date对象进行比较
            const dateA = new Date(a.expiredtm);
            const dateB = new Date(b.expiredtm);
            return dateA.getTime() - dateB.getTime();
        },
        sortDirections: ['descend', 'ascend'],
    },
    {
        title: '是否有效',
        dataIndex: 'isvalid',
        width: 50,
        slots: { customRender: 'isvalid' }
    },
    {
        title: '持证人id',
        dataIndex: 'holduserid',
        ifShow: false,
        width: 100,
    },
    {
        title: '持证人姓名',
        dataIndex: 'holdusername',
        width: 100,
    },
    {
        title: '是否为相关方',
        dataIndex: 'isepiboly',
        width: 50,
        ifShow: false,
        slots: { customRender: 'isepiboly' }
    },
    {
        title: '是否为人员资质证照',
        dataIndex: 'isperson',
        width: 100,
        ifShow: false,
        slots: { customRender: 'isperson' }
    },
]




